<% /**
	* login.jsp
	* 
	* Page containing the forms needed for a user to create a new account
	*
	* @author Chris Avery
	*/
%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="b1w1nn1ng.crossf1t.gui.*"%>
<%@page import="b1w1nn1ng.crossf1t.business.*"%>
<%@page import="b1w1nn1ng.crossf1t.db.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title> Create Account </title>
		<jsp:include page="/detectBrowser.jsp" />	
	</head>
	<body>
	
		<div id="container">
		<h1> Create Account </h1> <hr />
		<%
		
		String errorString = Login.validate(request);
				
		if(errorString.length() == 0) {
			//If we don't have any errors, then we can ship the completed user off to the database and
			//then display a confirmation page.
			System.out.println(request.getParameter("password1"));
			User newUser = new User(request.getParameter("username"), request.getParameter("password1"), 
					request.getParameter("email1"), request.getParameter("firstName"),
					request.getParameter("lastName"), request.getParameter("question"), 
					request.getParameter("answer"), Integer.parseInt(request.getParameter("weight")), 
					Integer.parseInt(request.getParameter("height")));
			Login.createAccount(newUser);
			out.println("Thank you! Your account was successfully created. You may click the button below "+
					"to return to the Account Settings screen!");
			out.println("<br/><input type=\"button\" class=\"submit\" value=\"Back\" onclick=\"window.location =\'login.jsp\'\"/>");
		} else {
			//display an error page.
			out.println("<div id=\"alignleft\">");
			out.println("There were one or more errors with the information you provided:");
			out.println("<ul>");
			out.println(errorString.toString());
			out.println("</ul>");
			out.println("<br/><input type=\"button\" class=\"submit\" value=\"Back\" onclick=\"window.location =\'loginCreateAccount.jsp\'\"/>");
		}
		 %>
		
		</div>
	</body>
</html>

